<?php

namespace app\admin\model;


/**
 * Author:Jack Wang
 * Time:2018-10-29 10:02:49
 * Describe:配置类型模型
 * Class ConfigType
 * @package app\admin\model
 */
class ConfigType extends Base
{

    //配置类型列表
    public function configTypeList($keyword = ""){
        $field_count = "num";
        $Config = new Config();
        $sql = $Config->getTypeBuildSql($field_count);
        return $this
            ->alias("a")
            ->field([
                "a.type_id",
                "a.type_name",
                "a.config_type",
                "IFNULL(b.".$field_count.",0) ".$field_count
            ])
            ->join($sql." b","a.config_type = b.config_type","left")
            ->where(function ($q)use ($keyword){
                if(!empty($keyword)){
                    $q->whereOr("a.type_name","like","%".$keyword."%")->whereOr("a.config_type","like","%".$keyword."%");
                }
            })
            ->page($this->after_page)
            ->limit($this->after_limit)
            ->select();
    }

    //配置类型列表总数
    public function configTypeListCount($keyword = ""){
        return $this
            ->alias("a")
            ->where(function ($q)use ($keyword){
                if(!empty($keyword)){
                    $q->whereOr("a.type_name","like","%".$keyword."%")->whereOr("a.config_type","like","%".$keyword."%");
                }
            })
            ->count();
    }

}